/**
 * Created by jiachneyu on 2018/3/16.
 */
const loginHandle = require('../model/login');
const md5 = require("md5")
let login = async (ctx,next) => {
    const req = ctx.request.body;
    console.log(req)
    await loginHandle(req.name,req.pwd).then(res=>{
        if(res.code === 1){
            ctx.cookies.set("cid",md5("jcy"+req.name+"jiachenyu",{
                path: "/",
                maxAge: 7200000,
                httpOnly:false
            }))
        }
        ctx.response.status = 200;
        ctx.body = res;
    });

}


module.exports = [
    {
        method: "post",
        path: "/api/blog/login",
        handle: login
    }
]
